<template>
  <div class="meteragereport-manage">
    <div class="right-box">
      <div class="operate_wrap flexDiv">
        <div class="flex-center">
          <el-button type="primary" size="small" class="add buildButtonStyle" @click="clickAdd('build')" v-permission="permission.add"><i class="iconfont icon-icon_add"></i> 新增
          </el-button>
          <el-button type="primary" size="small" class="add buildButtonStyle" @click="clickAddSon('build','进场')"><i class="iconfont icon-icon_add"></i> 进场登记
          </el-button>
          <el-button type="primary" size="small" class="add buildButtonStyle" @click="clickAddSon('build','出场')"><i class="iconfont icon-icon_add"></i> 出场登记
          </el-button>

          <el-upload class="upload-demo fill span18" style="display:none;" action="" :before-upload="submitImportExcel">
            <el-button id="excel-import-button" class="delete" style="margin: 0 10px;display:none;" size="small"><i class="iconfont icon-icon_zp"></i> 导入
            </el-button>
          </el-upload>

          <el-button type="primary" class="delete ml15" size="small" @click="importExcel" style="width: 88px;" v-permission="permission.add"><i class="iconfont icon-icon_zp"></i>&nbsp; 导入</el-button>

          <el-button class="delete" size="small" style="width: 110px;" @click="downfile">
            <i class="iconfont icon-daochu"></i> 模板下载
          </el-button>
        </div>

        <div class="flex-right">
          <el-select class="select" size="small" v-model="search.rylx" placeholder="请选择人员类型" @change="changePersonType" clearable>
            <el-option v-for="item in peopleStatusArr" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>

          <el-input class="input" size="small" v-model="search.personName" @change="changePersonName" placeholder="请输入姓名" clearable></el-input>

          <el-button class="search mr15" size="small" @click="onSearch"><i class="iconfont icon-sousuo"></i>&nbsp;搜索
          </el-button>

          <el-button class="search buildButtonStyle" size="small" @click="exportExcel()">&nbsp;导出</el-button>
        </div>
      </div>
      <div class="bottom-button-box WholeScroll" v-if="showPeopleNum">
        <div @click="selectButton(index)" v-for="(item,index) in buttonGroup" :key="index" class="flex-column button-box" :class="selectIndex==index?'selected':''">
          <p class="one-line-p">{{item.number}}<span>人</span></p>
          <p class="one-line-p">{{item.title}}</p>
        </div>
      </div>
      <div class="list_wrap WholeScroll" v-if="personType != '3'">
        <el-table class="table-four-blue" :border="true" :row-class-name="tableRowStyleName" :cell-class-name="tableCellStyleName" :header-cell-class-name="tableHeaderCellStyleName" :stripe="true" :data="list[0]" @cell-click="cellClick" style="width: 99%;margin-top:10px;" size="medium" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column show-overflow-tooltip label="序号" width="60">
            <template slot-scope="scope">
              <span>{{search.pageNo * search.pageSize + scope.row.listIndex + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="companyName" width="160" label="公司名称">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.companyName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="personName" label="姓名">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.personName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="idCard" width="160" label="身份证号码">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.idcardNo}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="post" label="岗位">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.postName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="CertificateStatus" label="证书状态">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.certificateStatus}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="inOutStatus" label="状态">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.inOutStatus}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="inTime" label="进场时间" min-width="120">
            <template slot-scope="scope">
              {{scope.row.entryDate}}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="outTime" label="出场时间" min-width="120">
            <template slot-scope="scope">
              {{scope.row.exitDate}}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip width="260" fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" v-permission="permission.show" class="menu_icon iconfont icon-icon_look action_color1" @click="showDialog('check','承包商信息查看',scope.row.id)">&nbsp;查看</el-button>
              <el-button size="mini" v-permission="permission.edit" class="menu_icon iconfont icon-xiugai-copy action_color1" @click="showDialog('edit','承包商信息编辑',scope.row.id)">&nbsp;修改</el-button>
              <el-button size="mini" v-permission="permission.del" class="menu_icon iconfont icon-shanchu action_color2" @click="showDialog('delete','承包商信息删除',scope.row.id)">&nbsp;删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="float: right; margin-top: 10px;" layout="prev, pager, next" :page-size="search.pageSize" :total="search.total" :current-page="search.pageNo + 1" :prev-text="tablePaginationPrev" :next-text="tablePaginationNext" @current-change="paginationChange">
        </el-pagination>
      </div>
      <div class="list_wrap WholeScroll" v-if="personType == '3'">
        <el-table class="table-six-blue" :border="true" :row-class-name="tableRowStyleName" :cell-class-name="tableCellStyleName" :header-cell-class-name="tableHeaderCellStyleName" :stripe="true" :data="list[0]" @cell-click="cellClick" style="width: 99%;margin-top:10px;" size="medium" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column show-overflow-tooltip label="序号" width="60">
            <template slot-scope="scope">
              <span>{{search.pageNo * search.pageSize + scope.row.listIndex + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="sectionName" width="160" label="标段">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.sectionName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="name" label="人员类型">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.personTypeName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="idCard" width="160" label="施工班组">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.teams}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="personName" label="姓名">
            <template slot-scope="scope">
              <div style="text-align: start">{{scope.row.personName}}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="inTime" label="进场日期" min-width="120">
            <template slot-scope="scope">
              {{scope.row.entryDate}}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="outTime" label="出场日期" min-width="120">
            <template slot-scope="scope">
              {{scope.row.exitDate}}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip width="230px" fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" v-permission="permission.show" class="menu_icon iconfont icon-icon_look action_color1" @click="showDialog('check','承包商信息查看',scope.row.id)">&nbsp;查看</el-button>
              <el-button size="mini" v-permission="permission.edit" class="menu_icon iconfont icon-xiugai-copy action_color1" @click="showDialog('edit','承包商信息编辑',scope.row.id)">&nbsp;修改</el-button>
              <el-button size="mini" v-permission="permission.del" class="menu_icon iconfont icon-shanchu action_color2" @click="showDialog('delete','承包商信息删除',scope.row.id)">&nbsp;删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="float: right; margin-top: 10px;" layout="prev, pager, next" :page-size="search.pageSize" :total="search.total" :current-page="search.pageNo + 1" :prev-text="tablePaginationPrev" :next-text="tablePaginationNext" @current-change="paginationChange">
        </el-pagination>
      </div>
    </div>

    <el-drawer size="60%" :before-close="handleClose" :visible.sync="leftDrawer" :with-header="false">
      <div class="drawerBox">
        <div class="title-box">
          <i class="iconfont icon-close" style="margin-right: 15px;font-size: 20px;cursor: pointer" @click="closeDrawer()"></i>{{chooseTitle}}
        </div>
        <div class="list_wrap" style="padding: 0 20px">
          <el-table class="table-three-blue" :border="true" :row-class-name="tableRowStyleName" :cell-class-name="tableCellStyleName" :header-cell-class-name="tableHeaderCellStyleName" :stripe="true" ref="multipleTable" :data="leftList" tooltip-effect="dark" @cell-click="cellClick2" style="width: 100%; font-family: PingFangSC-Regular; font-size: 14px">
            <el-table-column show-overflow-tooltip label="序号" width="60">
              <template slot-scope="scope">
                <span>{{search2.pageNo * search2.pageSize + scope.row.listIndex2 + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="proName" align="left" min-width="100" label="项目名称">
              <template slot-scope="scope">
                <div style="text-align: start">{{scope.row.proName}}</div>
              </template>

            </el-table-column>
            <el-table-column show-overflow-tooltip prop="contractName" align="left" min-width="160" label="合同名称">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.contractName}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="contractNumber" align="left" width="160" label="合同编号">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.contractNumber}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="contractMoney" align="left" width="150" label="合同金额（万元）">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.contractMoney}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="orderDate" align="left" width="120" label="签订日期">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.orderDate}}
                </div>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="float: right; margin-top: 30px" layout="prev, pager, next" :page-size="search2.pageSize" :total="search2.total" :current-page="search2.pageNo + 1" :prev-text="tablePaginationPrev" :next-text="tablePaginationNext" @current-change="paginationChange2">
          </el-pagination>
        </div>
      </div>
    </el-drawer>

    <el-drawer size="60%" :before-close="handleCloseRight" :visible.sync="rightDrawer" :with-header="false">
      <div class="drawerBox">
        <div class="title-box flex-row-center">
          <div>
            <i class="iconfont icon-close" style="margin-right: 15px;font-size: 20px;cursor: pointer" @click="closeDrawer"></i>{{chooseTitle}}
          </div>
          <div class="operate_wrap" style="justify-content: flex-end;width: unset;">
            <el-select style="margin: 0; margin-right: 15px;width: 250px;" class="select" size="small" v-model="search3.projectId" v-on:change="getDataByProjectId()" value-key="id" filterable placeholder="选择项目" clearable>
              <el-option v-for="item in projectTree" :key="item.id" :label="item.shortName" :value="item.id">
              </el-option>
            </el-select>
            <el-button v-permission="permission2.add" type="primary" size="small" class="add buildButtonStyle" @click="showDialogRight('build','新增信用评价')"><i class="iconfont icon-icon_add"></i> 新增
            </el-button>
          </div>
        </div>
        <div class="list_wrap" style="padding: 0 20px">
          <el-table class="table-two-blue" :border="true" :row-class-name="tableRowStyleName" :cell-class-name="tableCellStyleName" :header-cell-class-name="tableHeaderCellStyleName" :stripe="true" ref="multipleTable" :data="rightList" tooltip-effect="dark" @cell-click="cellClick3" style="width: 100%; font-family: PingFangSC-Regular; font-size: 14px">
            <el-table-column show-overflow-tooltip label="序号" type="index" width="57">
              <template slot-scope="scope">
                <span>{{search3.pageNo * search3.pageSize + scope.row.listIndex3 + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="proName" align="left" min-width="160" label="项目名称">
              <template slot-scope="scope">
                <div style="text-align: start">{{scope.row.proName}}</div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="contractNum" align="left" min-width="160" label="合同编号">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.contractNum}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="quarter" align="left" width="140" label="季度">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.quarter}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="score" align="left" width="80" label="评价扣分">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.score}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="userName" align="left" width="80" label="登记人">
              <template slot-scope="scope">
                <div style="text-align: left">
                  {{ scope.row.userName}}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="createTime" align="left" width="230" label="操作">
              <template slot-scope="scope">
                <el-button size="mini" v-permission="permission2.show" class="menu_icon iconfont icon-icon_look action_color1" @click="showDialogRight('check','信用评价查看',scope.row.id)">&nbsp;查看</el-button>
                <el-button size="mini" v-permission="permission2.edit" class="menu_icon iconfont icon-xiugai-copy action_color1" @click="showDialogRight('edit','信用评价编辑',scope.row.id)">&nbsp;修改</el-button>
                <el-button size="mini" v-permission="permission2.del" class="menu_icon iconfont icon-shanchu action_color2" @click="showDialogRight('delete','信用评价删除',scope.row.id)">&nbsp;删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="float: right; margin-top: 30px" layout="prev, pager, next" :page-size="search3.pageSize" :total="search3.total" :current-page="search3.pageNo + 1" :prev-text="tablePaginationPrev" :next-text="tablePaginationNext" @current-change="paginationChange3">
          </el-pagination>
        </div>
      </div>
    </el-drawer>

    <Detail :postDetail="postDetailData" @reloadList="getList(true)"></Detail>
    <dateDetail :postDetail="postDetailDataDate" @reloadList="getList(true)"></dateDetail>
  </div>
</template>

<script>
import {
  tableRowStyleGol,
  tableCellStyleGol,
  tableHeaderCellStyleGol,
  doCreateObject
} from '@/utils/publicFun'


import entryExitRegistration from '@/api/buss/entryExitRegistration'
import contractor from '@/api/buss/contractorManagement'
import msgUtil from '@/utils/msgUtil'
import crudDict from '@/api/system/dict'
export default {
  name: 'in-out-sign',
  components: {
    Detail: require(`./in-out-sign-detail`).default,
    dateDetail: require(`./chooseDateDetail`).default,
  },
  props: {
    chooseData: {
      type: Object,
      default: {

      }
    }
  },
  data() {
    return {
      selectIndex: '',
      buttonGroup: [{
        number: 0,
        title: '登记人数'
      }, {
        number: 0,
        title: '在场人数'
      }, {
        number: 0,
        title: '退场人数'
      }, {
        number: 0,
        title: '一般作业人员'
      }, {
        number: 0,
        title: '特种作业人员'
      }, {
        number: 0,
        title: '男性人数'
      }, {
        number: 0,
        title: '女性人数'
      }, {
        number: 0,
        title: '1960~1969'
      }, {
        number: 0,
        title: '1970~1979'
      }, {
        number: 0,
        title: '1980~1989'
      }, {
        number: 0,
        title: '1990~1999'
      }, {
        number: 0,
        title: '2000~2009'
      }],
      peopleStatusArr: [{
        value: 'all',
        label: '所有人员'
      }, {
        value: 'in',
        label: '在场人员'
      }, {
        value: 'out',
        label: '出场人员'
      }],
      scoreArray: [],
      contractorManagementId: '',
      contractorCompanyName: '',
      projectTree: [],
      leftList: [{}],
      rightList: [{}],
      chooseLeftIndex: null,
      permission: {//承包商的权限
        add: ['100', '1001066:add'],
        show: ['100', '1001066:show'],
        edit: ['100', '1001066:edit'],
        del: ['100', '1001066:del'],
      },

      permission2: {//信用评价的权限
        add: ['100', '1000204:add2'],
        show: ['100', '1000204:show2'],
        edit: ['100', '1000204:edit2'],
        del: ['100', '1000204:del2'],
      },
      tableRowStyleName: tableRowStyleGol,
      tableCellStyleName: tableCellStyleGol,
      tableHeaderCellStyleName: tableHeaderCellStyleGol,
      tablePaginationPrev: '上一页',
      tablePaginationNext: '下一页',
      title: '',
      showSelectDialog: false,
      showReportDialog: false,
      selectedIds: [],
      postList: [],
      projectId: '',
      personType: '',
      personTypeList: [],
      // 搜索参数
      search: {
        total: 0,
        pageIndex: 0,
        pageNo: 0,
        pageSize: 10,
        pageSum: 0,
        personName: '',
        sectionId: '',
        rylx: '',
        personTypeList: [],
        inOutStatus: '',
        personType: '',
        gender: '',
        birthStart: '',
        birthEnd: '',
      },
      searchNum: {
        total: 0,
        pageIndex: 0,
        pageNo: 0,
        pageSize: 10,
        pageSum: 0,
        personName: '',
        sectionId: '',
        rylx: '',
        personTypeList: [],
      },
      search2: {
        total: 0,
        pageNo: 0,
        pageIndex: 0,
        pageSize: 10,
        pageSum: 0,
        name: ''
      },

      search3: {
        total: 0,
        pageNo: 0,
        pageIndex: 0,
        pageSize: 10,
        pageSum: 0,
        name: '',
        projectId: '',
      },

      reportList: [
        {
          id: '施工单位',
          name: '施工单位',
        },
        {
          id: '监理单位',
          name: '监理单位',
        },
        {
          id: '中心试验室单位',
          name: '中心试验室单位',
        },
        {
          id: '设计单位',
          name: '设计单位',
        },
        {
          id: '勘察单位',
          name: '勘察单位',
        },
        {
          id: '检测单位',
          name: '检测单位',
        },
        {
          id: '其他',
          name: '其他',
        },
        /* {id:'检测单位',
           name:'检测单位',},*/
      ],

      postDetailData: {
        show: false,
        type: 'build'
      },
      postDetailDataDate: {
        show: false,
        type: 'build'
      },
      postSonData: {
        show: false,
        type: 'build',
        typeName: '新增',
      },
      list: [],
      data: {},

      activeName: 'first',

      navigationIndex: 0,
      chooseTitle: '',
      rightDrawer: false,
      leftDrawer: false,
      showPeopleNum: false,
      showSonList: false
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$set(this, 'chooseLeftIndex', 0)
      this.intiClick(this.search.tableId, this.chooseLeftIndex);
    })
  },
  watch: {
    'chooseData': {
      immediate: true,
      handler(val) {
        this.search.sectionId = val.id
        this.searchNum.sectionId = val.id
        this.projectId = val.pid
        this.personType = val.personType
        if (val.personType == '3') {
          this.showPeopleNum = true
        } else {
          this.showPeopleNum = false
        }
        this.getPostList()
        this.getPersonType()
      },
      deep: true
    },
    list(val) {
      console.log(val, '123')
    },
  },
  methods: {
    importExcel() {
      $("#excel-import-button").trigger("click");
    },
    onSearch() {
      this.search.pageNo = 0
      this.search.total = 0
      this.getList()
    },
    changePersonName() {
      this.searchNum.personName = this.search.personName
      this.onSearch()
    },
    changePersonType() {
      this.searchNum.rylx = this.search.rylx
      this.onSearch()
    },
    clearSearch() {
      for (let key in this.search) {
        if (key === 'inOutStatus') {
          delete this.search[key]
        }
        if (key === 'personType') {
          delete this.search[key]
        }
        if (key === 'gender') {
          delete this.search[key]
        }
        if (key === 'pageIndex') {
          this.search.pageIndex = 0
        }
        if (key === 'birthStart') {
          delete this.search[key]
        }
        if (key === 'birthEnd') {
          delete this.search[key]
        }
      }
    },
    selectButton(val) {
      this.clearSearch();
      this.selectIndex = val
      switch (val) {
        case 1:
          //在场人数
          this.search.inOutStatus = '进场';
          break;
        case 2:
          //退场人数
          this.search.inOutStatus = '出场';
          break;
        case 3:
          //一般作业人员
          this.personTypeList.forEach(item => {
            if (item.name == '一般作业人员') {
              this.search.personType = item.id;
            }
          })
          break;
        case 4:
          //特种作业人员
          this.personTypeList.forEach(item => {
            if (item.name == '特种作业人员') {
              this.search.personType = item.id;
            }
          })
          break;
        case 5:
          //男性人员
          this.search.gender = '1';
          break;
        case 6:
          //女性人员
          this.search.gender = '2';
          break;
        case 7:
          //1960-1969
          this.search.birthStart = '1960';
          this.search.birthEnd = '1969';
          break;
        case 8:
          //1970-1979
          this.search.birthStart = '1970';
          this.search.birthEnd = '1979';
          break;
        case 9:
          //1980-1989
          this.search.birthStart = '1980';
          this.search.birthEnd = '1989';
          break;
        case 10:
          //1990-1999
          this.search.birthStart = '1990';
          this.search.birthEnd = '1999';
          break;
        case 11:
          //2000-2009
          this.search.birthStart = '2000';
          this.search.birthEnd = '2009';
          break;

      }

      this.getList();

    },
    getPeopleNum() {
      entryExitRegistration.getPeopleNum(this.searchNum).then(res => {
        this.buttonGroup.forEach(item => {
          if (item.title === '登记人数') {
            item.number = res.data.amount
          }
          if (item.title === '在场人数') {
            item.number = res.data.innerNum
          }
          if (item.title === '退场人数') {
            item.number = res.data.outNum
          }
          if (item.title === '一般作业人员') {
            item.number = res.data.normalPersonNum
          }
          if (item.title === '特种作业人员') {
            item.number = res.data.specialOperationNum
          }
          if (item.title === '男性人数') {
            item.number = res.data.male
          }
          if (item.title === '女性人数') {
            item.number = res.data.female
          }
          if (item.title === '1960~1969') {
            item.number = res.data.old1
          }
          if (item.title === '1970~1979') {
            item.number = res.data.old2
          }
          if (item.title === '1980~1989') {
            item.number = res.data.old3
          }
          if (item.title === '1990~1999') {
            item.number = res.data.old4
          }
          if (item.title === '2000~2009') {
            item.number = res.data.old5
          }
        })
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError(this.$route.name + '请求失败')
      })
    },
    //  下载模板
    downfile() {
      let name = ''
      if (this.personType == '1') {
        name = 'personArchiveLy'
      } else if (this.personType == '2') {
        name = 'personArchiveYb'
      } else {
        name = 'personArchiveZy'
      }
      entryExitRegistration.downfile(this.search, name).then(res => {
        if (this.personType == '1') {
          doCreateObject(res, '人员档案模板_履约人员.xlsx')
        } else if (this.personType == '2') {
          doCreateObject(res, '人员档案模板_一般管理人员.xlsx')
        } else {
          doCreateObject(res, '人员档案模板_作业人员.xlsx')
        }

      }).catch(e => {
        console.log(e);
        this.$messageError("请求excel模板失败")
      })
    },
    getPersonType() {
      this.search.personTypeList = []
      crudDict.getByCode('personnelType').then(res => {
        if (res.code === 200) {
          var data = res.data;
          this.personTypeList = data
          for (var i in data) {
            if (this.personType == '1') {
              if (data[i].name == '履约人员') {
                this.search.personTypeList.push(data[i].id);
              }
            } else if (this.personType == '2') {
              if (data[i].name == '一般管理人员') {
                this.search.personTypeList.push(data[i].id);
              }
            } else {
              if (data[i].name != '履约人员' && data[i].name != '一般管理人员') {
                this.search.personTypeList.push(data[i].id);
                this.searchNum.personTypeList.push(data[i].id);
              }
            }
          }
          this.getList()
        } else {
          msgUtil.error2(res.data.message)
        }
      }).catch(() => {
        msgUtil.error2("获取人员类型失败")
      })
    },
    postShow(val) {
      this.postList.forEach(item => {
        if (item.value == val) {
          val = item.name
        }
      })
    },
    getPostList() {
      crudDict.getByCode('post').then(res => {
        if (res.code === 200) {
          var data = res.data;
          for (var i in data) {
            this.postList.push({ 'value': data[i].id, 'name': data[i].name });
          }
        } else {
          msgUtil.error2(res.data.message)
        }
      }).catch(() => {
        msgUtil.error2("获取人员类型失败")
      })
    },
    handleSelectionChange(val) {
      this.selectedIds = []
      val.forEach(item => {
        this.selectedIds.push(item.id)
      })
    },

    exportExcel() {
      //条件自己写咩

      let params = {
        sectionId: this.search.sectionId,
        personName: this.search.personName,
        rylx: this.search.rylx,
        leftType: this.personType,
        personTypeList: this.search.personTypeList
      }
      entryExitRegistration.exportExcel(params).then(res => {
        doCreateObject(res, '进出场登记.xls')
      })
    },
    getYearData(item) {
      getDetailedScoreData(item.id).then(res => {
        console.log(res)
        let arr = []
        let array = []
        for (let i in res) {
          console.log(i)
          arr = []
          arr.name = i
          arr.content = res[i]
          array.push(arr)
        }
        console.log(array, 'array')
        this.$set(this, 'scoreArray', array.reverse())
      }).catch(res => {
        console.log(res)
      })
    },
    closeDrawer() {
      this.rightDrawer = false
      this.leftDrawer = false
      this.getList()

    },
    showPerformancePerson(val) {
      this.showSonList = true


      let title = ''
      if (val.projectId == undefined || val.projectId == '') {
        title = '履约人员（' + val.companyName + '-' + val.contractNumber + ')'
      } else {
        title = '履约人员（' + val.companyName + '-' + val.proName + '-' + val.contractNumber + ')'
      }

      let projectId = val.projectId
      let projectName = val.proName
      let companyName = val.companyName
      let contractName = val.contractName
      let contractId = val.linkedContractId


      this.postSonData = {
        showList: true,
        //detailId: detailId,
        title: title,
        projectId: projectId,
        contractId: contractId,
        companyName: companyName,
        projectName: projectName,
        contractName: contractName,
      }

    },


    cellClick2(row, column, cell, event) {
      /*if (column.property === 'proName' ) {
        this.showDialogRight('check','信用评价查看',row.id)
      }*/
      if (column.property === 'contractName') {
        this.showDialog('contractCheck', '合同登记查看', row.linkedContractId)
      }
    },


    cellClick3(row, column, cell, event) {
      if (column.property === 'proName') {
        this.showDialogRight('check', '信用评价查看', row.id)
      }
    },

    // 点击单元格 任务名称展示详情
    cellClick(row, column, cell, event) {
      let contractNum = row.contractNum
      let companyName = row.enterpriseName
      let id = row.id
      this.contractorManagementId = row.id
      this.contractorCompanyName = row.enterpriseName

      if (column.property === 'personName') {
        this.handleClickDeal({
          type: 'show',
          detailId: row.id,
          actions: row.actions,
        })
      }
      // if(contractNum != 0){//若有关联合同，则允许弹出子界面
      if (column.property === 'contractNum') {
        this.leftDrawer = true
        this.rightDrawer = false
        this.chooseTitle = '相关项目（' + companyName + '）'
        this.getContractByCompanyName()
      }
      // if (column.property === 'totalScore') {
      //   this.leftDrawer = false
      //   this.rightDrawer = true
      //   this.chooseTitle = '信用评价（'+companyName+'）'
      //   this.getDataByProjectId()
      //   this.getProjectByCompanyName(id)
      // }
      //}
    },

    getContractByCompanyName() {
      this.leftList = []
      let params = {
        id: this.contractorManagementId,
        pageSize: this.search2.pageSize,
        pageNo: this.search2.pageNo,
      }
      contractor.getContractByCompanyName(params).then(res => {
        if (res.status == 200) {
          if (res.datalist) {
            this.leftList = res.datalist.list
            this.leftList.forEach((item, index) => {
              item.listIndex2 = index
            })

            this.search2.total = res.datalist.total
          }
        } else {
          msgUtil.error2('请先在合同登记中，维护该单位的项目合同')
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        msgUtil.error2('获取相关合同列表失败!')
      })

    },



    getProjectByCompanyName(val) {
      this.projectTree = []
      contractor.getProjectByCompanyName(val).then(res => {
        if (res.code == 200) {
          if (res.data.length > 0) {
            this.projectTree = res.data
          }
        } else {
          msgUtil.error2(res.msg)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        msgUtil.error2('获取项目列表失败!')
      })

    },


    getDataByProjectId() {
      this.rightList = []
      let param = {
        contractorManagementId: this.contractorManagementId,
        pageNo: this.search3.pageNo,
        pageSize: this.search3.pageSize,
      }
      if (this.search3.projectId != undefined && this.search3.projectId != '') {
        param.projectId = this.search3.projectId
      }
      contractor.creditEvaluationPaging(param).then(res => {
        if (res.code == 200) {
          if (res.data.content.length > 0) {
            this.$set(this, 'rightList', res.data.content)
            this.rightList.forEach((item, index) => {
              item.listIndex3 = index
            })

            this.search3.total = res.data.totalElements
          }
        } else {
          msgUtil.error2(res.msg)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        msgUtil.error2('获取信用评价列表失败!')
      })

    },


    handleClose(done) {
      this.rightDrawer = false
      this.leftDrawer = false
      this.getList()
      done();

    },

    handleCloseRight(done) {
      this.rightDrawer = false
      this.leftDrawer = false
      this.getList()
      done();

    },
    //  提交excel导入文件选择（承包商）
    submitImportExcel(file) {
      let fd = new FormData()
      fd.append('file', file)
      fd.append('type', this.personType)
      fd.append('sectionId', this.search.sectionId)
      fd.append('projectId', this.projectId)
      fd.append('Content-Type', 'multipart/form-data; boundary=----WebKitFormBoundaryIOi8qEBAFV1KN25n')
      entryExitRegistration.importExcel(fd).then(res => {
        if (res.code == 200) {
          console.log(`成功导入数据`)
          this.$messageSuccess("成功导入数据")
          this.getList(true)
        } else {
          this.$messageError("请求导入excel失败:" + res.msg)
          console.log("请求导入excel失败:" + res.msg)
        }
      }).catch(e => {
        console.log(e);
      })
    },
    keydown() {
      if (event.keyCode == 13) {
        this.getList(true)
      }
    },
    clickAdd(val) {
      this.showDetailDialog(val)
    },

    clickAddSon(type, name) {
      if (this.selectedIds.length == 0) {
        msgUtil.error2("请先选择人员档案")
        return
      }
      switch (type) {
        case 'build':
          this.postDetailDataDate = {
            show: true,
            type: type,
            typeName: name,
            detailId: '',
            selectedIds: this.selectedIds
          }
          break
      }
    },
    /*  操作 */
    showDialog(type, typeName, detailId) {//承包商列表页操作按钮的处理
      let params = {}
      switch (type) {
        case 'build':
          params.showPeopleNum = this.showPeopleNum
          params.projectId = this.projectId
          params.personType = this.personType
          this.postDetailData = {
            show: true,
            type: type,
            typeName: typeName,
            params,
            detailId: '',
          }
          break
        case 'edit':
          params.showPeopleNum = this.showPeopleNum
          params.projectId = this.projectId
          params.personType = this.personType
          this.postDetailData = {
            show: true,
            type: type,
            typeName: typeName,
            params,
            detailId: detailId,
          }
          break
        case 'check':
          params.showPeopleNum = this.showPeopleNum
          params.projectId = this.projectId
          params.personType = this.personType
          this.postDetailData = {
            show: true,
            type: type,
            typeName: typeName,
            params,
            detailId: detailId,
          }
          break
        case 'delete':
          if (detailId === '') {
            msgUtil.error2('请先选择要删除的记录！')
            return
          }
          msgUtil.confirm('确认删除该条数据?').then(res => {
            let idlist = []
            idlist.push(detailId)
            let param = {
              ids: idlist
            }
            entryExitRegistration.del(param).then(res => {
              if (res.code === 200) {
                msgUtil.success2('删除成功!')
                this.getList()
              } else {
                msgUtil.error2(res.data.message)
              }
            })
          })
          break

      }
    },
    showDialogRight(type, typeName, detailId) {//信用评价列表中操作按钮的点击处理
      switch (type) {
        case 'build':
          this.postDetailDataRight = {
            show: true,
            type: type,
            typeName: typeName,
            detailId: '',
            companyName: this.contractorCompanyName,
            contractorManagementId: this.contractorManagementId
          }
          break
        case 'edit':
          this.postDetailDataRight = {
            show: true,
            type: type,
            typeName: typeName,
            detailId: detailId,
            companyName: this.contractorCompanyName,
            contractorManagementId: this.contractorManagementId
          }
          break
        case 'check':
          this.postDetailDataRight = {
            show: true,
            type: type,
            typeName: typeName,
            detailId: detailId,
            companyName: this.contractorCompanyName,
            contractorManagementId: this.contractorManagementId
          }
          break
        case 'delete':
          if (detailId === '') {
            msgUtil.error2('请先选择要删除的记录！')
            return
          }
          msgUtil.confirm('确认删除该条数据?').then(res => {
            let idlist = []
            idlist.push(detailId)
            let param = {
              ids: idlist
            }
            entryExitRegistration.creditEvaluationDelete(param).then(res => {//删除信用评价
              if (res.code === 200) {
                msgUtil.success2('删除成功!')
                this.getDataByProjectId()
              } else {
                msgUtil.error2(res.data.message)
              }
            })
          })
          break

      }
    },
    // 切换列表
    paginationChange(index) {
      this.search.pageNo = index - 1
      this.getList()
    },

    paginationChange2(index) {
      this.search2.pageNo = index - 1
      this.getContractByCompanyName()
    },

    paginationChange3(index) {
      this.search3.pageNo = index - 1
      this.getDataByProjectId()
    },


    intiClick(val, index) {
      this.chooseLeftIndex = index
      this.search.pageNo = 0
      this.getList(true);
    },


    // 获取列表 api
    getList() {
      entryExitRegistration.getTablePage(this.search).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.list = []
          res.data.content.forEach((item, index) => {
            item.listIndex = index
          })

          this.$set(this.list, this.list.length, res.data.content)
          this.search.total = parseInt(res.data.totalElements)
          if (this.showPeopleNum) {
            this.getPeopleNum()
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('请求失败')
      })
    },

    goback() {
      let row = {
        projectName: this.search.projectName,
        projectId: this.search.projectId
      };
      this.$goRouteName('demolition-cost-detail', { row: row })
    },


    handleNodeClick(item, index) {
      this.intiClick(item.id, index)
    },
    // 显示详情弹窗 不同状态
    showDetailDialog(flag, params) {
      switch (flag) {
        case 'build':
          let type = this.$parent.nowChooseData.type
          console.log("type=", type)
          if (type && (type == "person" || type == 'project')) {
            this.$messageWarning("请先选择标段/合同段")
            return;
          }
          params = {}
          params.showPeopleNum = this.showPeopleNum
          params.projectId = this.projectId
          params.sectionId = this.search.sectionId
          params.personType = this.personType
          this.postDetailData = {
            show: true,
            type: 'build',
            params: params
          }
          break
        //查看
        case 'show':
          params.tableName = this.search.tableName;
          params.projectId = this.projectId,
            params.sectionId = this.search.sectionId,
            params.personType = this.personType,
            this.postDetailData = {
              show: true,
              type: 'check',
              detailId: params.detailId,
              params: params
            }
          break
      }
    },


    // 列表的操作流程
    handleClickDeal(res) {
      let type = res.type
      let detailId = res.detailId
      let url = res.url
      let name = res.name
      let actions = res.actions
      this.boundContractId = detailId
      // console.log(res)
      switch (type) {
        // 查看
        case 'show':
          // 显示详情弹窗
          this.showDetailDialog(type, {
            detailId: detailId,
            actions: actions
          })
          break
      }
    },
  },
}
</script>

<style scoped lang="scss">
.bottom-button-box {
  display: flex;
  align-items: center;
  flex-direction: row;
  flex-wrap: nowrap;
  width: 100%;
  overflow-x: auto;
  padding-bottom: 15px;
  .button-box {
    border-radius: 5px;
    background-color: white;
    cursor: pointer;
    margin-right: 20px;
    margin-top: 15px;
    min-width: 110px;
    border: 1px solid rgba(144, 144, 144, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    p {
      padding: 0;
      margin: 0 30px;
      white-space: nowrap;
    }
    p:nth-of-type(1) {
      font-size: 16px;
      font-weight: bold;
      margin-top: 10px;
    }

    p:nth-of-type(2) {
      font-size: 12px;
      margin-bottom: 10px;
    }

    span {
      font-size: 12px;
    }
  }
  .button-box.selected {
    background-color: #09abf6;
    p {
      color: white;
    }
    span {
      color: white;
    }
  }
}

.navigation2 {
  width: 100%;
  height: 40px;
  box-sizing: border-box;
  border-bottom: 1px solid #313e50;
  margin-top: 5px;
  border-bottom: 1px solid #e2e8ec !important;
  .el-button {
    height: 40px;
    border: 1px solid #374256;
    font-family: PingFangSC-Regular;
    border-radius: 5px 5px 0 0;
    min-width: 95px;
    font-size: 14px;
    color: #8190a7;
    background: #09abf6 !important;
    border: 1px solid #09abf6 !important;
    color: #fff !important;
    border-bottom: none !important;
    &:hover {
      background-color: #f2f2f2 !important;
      color: #2aa7dc !important;
    }
  }
  /*选中样式*/
  .el-button[selected] {
    border: 1px solid #2aa7dc !important;
    border-bottom: 1px solid #f2f2f2 !important;
    color: #2aa7dc !important;
    background-color: #f2f2f2 !important;
  }
}
.operate_wrap2 {
  display: flex;
  align-items: center;
  height: 40px;
  width: 100%;
  box-sizing: border-box;

  .el-button,
  .el-select,
  .el-input {
    border-radius: 4px;
    font-family: PingFangSC-Medium;
    font-size: 14px;
    display: inline-block;
  }

  .el-date-editor--daterange {
    width: 300px;
  }

  .delete {
    width: 88px;
  }

  .search {
    width: 88px;
    float: right;
    color: #fff;
    margin-left: 10px;
  }

  .el-select {
    width: 140px;
    margin-left: 10px;
  }

  .input {
    width: 140px;
    float: right;
    margin-left: 10px;
    color: #3e556e;
  }
}

.operate_wrap {
  height: 40px;
  width: 100%;
  box-sizing: border-box;
  .select {
    width: 150px;
    margin-right: 15px;
  }
  .input {
    width: 150px;
    margin-right: 15px;
  }
  .mr15 {
    margin-right: 15px;
  }
  .search {
    width: 88px;
    color: #fff;
    margin-left: 0 !important;
  }
  .mr15 {
    margin-right: 15px;
  }
  .ml15 {
    margin-left: 15px !important;
  }
}
.list_wrap {
  margin-top: 20px;
}
.rowFileImg {
  cursor: pointer;
  width: 18px;
}
.flex-row {
  display: flex;
  flex-direction: row;
}
.flex-row-hv {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.left-box {
  min-width: 200px;
  border-right: 1px #e2e8ec solid;
  p {
    cursor: pointer;
    font-size: 14px;
  }
}
.right-box {
  width: 100%;
}
.chooseText {
  color: #3270ef;
}
.buttonDiv {
  position: absolute;
  cursor: pointer;
  width: 11px;
  font-size: 14px;
  top: 44%;
  height: 60px;
  line-height: 60px;
  color: #ffffff;
  z-index: 1;
  transition: left 1s;
  -moz-transition: left 1s; /* Firefox 4 */
  -webkit-transition: left 1s; /* Safari and Chrome */
  -o-transition: left 1s; /* Opera */
}

.buttonLeft {
  left: -15px;
  background: rgb(55, 66, 86);
  border-radius: 0 8px 8px 0;
}

.buttonRight {
  left: calc(12% - 11px);
  background: #33475d;
  border-radius: 8px 0 0 8px;
}

.demoClass {
  text-align: left !important;
}

.as-button-hidden {
  display: unset;
  width: 0px;
  height: 0px;
  position: absolute;
  opacity: 0%;
}
/*.show-ellipsis {*/
/*display: block;*/
/*width: 100%;*/
/*overflow: hidden;*/
/*white-space: nowrap;*/
/*text-overflow: ellipsis;*/
/*}*/
.omit {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-box {
  font-size: 16px;
  font-weight: bold;
  color: rgba(0, 0, 0, 0.85);
  margin: 17px;
}
.flex-row-center {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.pstyle {
  p {
    padding: 5px 15px;
    margin: 0;
  }
}
</style>
